<template>
    <el-input class="vip_count" v-model="showMinPrice" style="width: 120px;" placeholder="请输入"></el-input>
</template>
  
<script setup lang="ts">
const props = withDefaults(defineProps<{
    modelValue?: number | null | string, // showMinPrice
}>(), {
    // modelValue1: null,
    // modelValue: null,
})
const modelValueRef = toRef(props, 'modelValue')

const emits = defineEmits(['update:model-value'])


const showMinPrice = ref()
watch(showMinPrice, (newValue) => {
    emits("update:model-value", isNaN(Number(newValue)) ? newValue : parseInt((Number(newValue) * 100).toFixed(2).slice(0, -3)))
})
watch(modelValueRef, (newValue) => {
    showMinPrice.value = isNaN(Number(newValue)) ? newValue : Number(newValue) / 100
})

onMounted(() => {
    showMinPrice.value = isNaN(Number(modelValueRef.value)) ? modelValueRef.value : Number(modelValueRef.value) / 100
})


const isEmpty = (val: any) => {
    return val === null || val === undefined || val === ''
}

const rules = [{
    required: true,
    trigger: 'blur',
    validator(rule: any, val: any, callback: any) {
        if (isEmpty(props.modelValue) || isEmpty(props.modelValue)) {
            callback(new Error('请填写商品原价'))
        } else {
            callback()
        }
    },
}]
</script>
  